//
//  String.swift
//  readtool
//
//  Created by WanJiading on 16/6/6.
//  Copyright © 2016年 DAD. All rights reserved.
//

import UIKit

extension String {
    func isPhoneNumber() -> Bool {
        // 1开头 后10个数字
        let phoneRegex: String = "^1[\\d]{10}$"
        let fmt: String = "SELF MATCHES %@"
        let phoneTest: NSPredicate = NSPredicate(format: fmt, phoneRegex)
        return phoneTest.evaluate(with: self)
        
//        let phoneTest: Predicate = Predicate(format: fmt, phoneRegex)
//        return phoneTest.evaluate(with: self)
    }
    
    
    func judgeEnglishLrc() -> Bool {
        
        let lrcString = self as NSString
        
        if lrcString.length > 10 {
            
            let range1 = NSRange.init(location: 0, length: 1)
            let range2 = NSRange.init(location: 3, length: 1)
            let range3 = NSRange.init(location: 6, length: 1)
            let range4 = NSRange.init(location: 9, length: 1)

            let string1 = lrcString.substring(with: range1)
            let string2 = lrcString.substring(with: range2)
            let string3 = lrcString.substring(with: range3)
            let string4 = lrcString.substring(with: range4)
            
            if string1 == "[" && string2 == ":" && string3 == "." && string4 == "]" {
                
                return true
            }
        }
        
        return false
    }
    
    
    func judgeChineseLrc() -> Bool {
        
        let lrcString = self as NSString
        
        if lrcString.length > 4 {
            
            let range1 = NSRange.init(location: 0, length: 1)
            let range2 = NSRange.init(location: 1, length: 1)
            let range3 = NSRange.init(location: 2, length: 1)
            let range4 = NSRange.init(location: 3, length: 1)
            
            let string1 = lrcString.substring(with: range1)
            let string2 = lrcString.substring(with: range2)
            let string3 = lrcString.substring(with: range3)
            let string4 = lrcString.substring(with: range4)
            
            if string1 == "[" && string2 == "C" && string3 == "N" && string4 == "]" {
                
                return true
            }
        }
        
        return false
    }
	
}
